<template>
	 <el-row>
        <el-upload
          :action="dev+params.name" name="files"
          list-type="picture-card"
          :on-preview="preview"
          :on-remove="remove"
          :on-success="success"
		  :on-error="error"
          :file-list="params.picList"
		  :headers="token"
		  :limit="5">
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible" size="tiny">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
		</el-row>
</template>
<script>
  import _ from 'lodash'
  import {IMGPATH,IMGSERVER} from '../../common/js/constant'
	export default{
		props:["params","uploadSuccess","uploadRemove","picList"],
		name:'imgupload',
		data(){
			return {
        		dialogImageUrl: '',
        		dialogVisible: false,
        		dev:IMGPATH,
        		files:[],
			    token:{
					s_company_token:this.$store.getters.s_company_token
				},
				pic_list:[]
			}
		},
		methods:{
		   remove(file) {
		      let res = file.hasOwnProperty("response");
		       if(res){
		       		_.remove(this.pic_list, item=>{
						return item == IMGSERVER+file.response.data;
					});
		    		this.uploadRemove(this.pic_list);
		       }
		       else{
					_.remove(this.pic_list, item=>{
						return item == file.url;
					});
		    		this.uploadRemove(this.pic_list);
		       }	
		  },
		  preview(file) {
		    this.dialogImageUrl = file.url;
		    this.dialogVisible = true;
		  },
		  success(file){
		  	this.pic_list.push(IMGSERVER+file.data);
		    this.uploadSuccess(this.pic_list);
		  },
			error(){
				alert("上传失败，感谢您的使用")
			}
		},
		created(){
		   for(let key in this.picList){
		   	 this.pic_list.push(this.picList[key].url)
		   }
		}

	}
</script>
